/**
 * 项目名：化工企业安全生产信息化管理平台
 * 日期：    2020-03-01 22:19:07
 * Copyright (c) 2015- -版权所有
 */

package com.joysuch.wwyt.edu.repository;

import com.joysuch.wwyt.edu.entity.EduCourseCourseware;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;

import java.util.List;

/**
 * EduCourseCoursewareDao
 *
 */
public interface EduCourseCoursewareDao
        extends JpaRepository<EduCourseCourseware, Long>, QuerydslPredicateExecutor<EduCourseCourseware> {
    public Page<EduCourseCourseware> findAll(Specification<EduCourseCourseware> spec, Pageable pageable);

    public EduCourseCourseware save(EduCourseCourseware bean);

    public void delete(EduCourseCourseware bean);

    public int deleteByCoursewareId(Long courseWareId);

    public int deleteByCourseId(Long courseId);

    public int deleteByCourseIdAndCoursewareId(Long courseId, Long coursewareId);

    @Query("select coursewareId from EduCourseCourseware where courseId = ?1")
    List<Long> findCoursewareIdsByCourseId(Long courseId);

    @Query(value = "select count(1) from wwyt_edu_course_courseware where COURSEWARE_ID = ?1 and delete_flag = '0'",nativeQuery = true)
    Long countOfCoursewareId(Long coursewareId);

    EduCourseCourseware findByCoursewareIdAndCourseId(Long ex, Long courseId);
}
